package entity.result;


import enums.http.ResponseCodeEnum;

import java.util.List;

/**
 * 分页查询返回
 */
public class PageResult<T> extends BaseResult {

	private static final long serialVersionUID = 3282033288991252842L;
	private List<T> data;
	private Integer totalCount;


	public PageResult() {
	}

	public PageResult(int totalCount, List<T> data) {
		this.setSuccess(true);
		this.setCode(ResponseCodeEnum.SUCCESS.getCode());
		this.setTotalCount(totalCount);
		this.setData(data);
	}

	public PageResult(List<T> data) {
		this.setSuccess(true);
		this.setCode(ResponseCodeEnum.SUCCESS.getCode());
		this.setTotalCount(0);
		this.setData(data);
	}

	public List<T> getData() {
		return data;
	}

	public void setData(List<T> data) {
		this.data = data;
	}

	public Integer getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(Integer totalCount) {
		this.totalCount = totalCount;
	}

	/**
	 * 响应成功
	 */
	public PageResult<T> responseSuccess(List<T> data,int totalCount) {
		super.responseSuccess();
		this.setData(data);
		this.setTotalCount(totalCount);
		return this;
	}
	
	/**
	 * 响应成功
	 */
	public PageResult<T> responseSuccess(List<T> data) {
		super.responseSuccess();
		this.setData(data);
		return this;
	}

	/**
	 * 响应失败
	 */
	public PageResult<T> responseFail(ResponseCodeEnum responseCodeEnum) {
		super.responseFail(responseCodeEnum);
		return this;
	}

	/**
	 * 响应失败
	 */
	public PageResult<T> responseFail(ResponseCodeEnum responseCodeEnum, String message) {
		super.responseFail(responseCodeEnum, message);
		return this;
	}
}
